package com.twt.recruit.controller;


import com.twt.recruit.service.FileService;
import com.twt.recruit.utils.response.ResultBody;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1")
public class FileController {

    private final static Logger logger = LoggerFactory.getLogger(FileController.class);

    @Resource
    FileService fileService;


    @PostMapping("/user/img")
    @Operation(summary = "上传图片")
    public ResultBody uploadImg(@RequestParam MultipartFile file){
        try {
            String filePath = fileService.upload(file);
            return ResultBody.success(filePath);
        }catch (Exception e){
            logger.error("上传图片失败", e);
            return ResultBody.error("上传图片失败");
        }
    }

}
